<template>
  <div class="searchHistory">
    <!-- 标题 -->
    <van-cell title="搜索历史" v-if="show">
      <template>
        <van-icon name="delete-o" @click="show=false"/>
      </template>
    </van-cell>
    <van-cell title="搜索历史" v-else>
      <template >
        <div class="right-text">
          <!-- <span @click="history.splice(0)">全部删除</span> -->
          <span @click="$emit('deleteall')">全部删除</span>
          <span style="margin-left:8px" @click="show=true">完成</span>
        </div>
      </template>
    </van-cell>
    <van-cell @click="onclickitem(item)" :title="item" v-for="item in history" :key="item">
      <template v-if="!show">
        <van-icon name="close" />
      </template>
    </van-cell>

  </div>
</template>

<script>
export default {
  data () {
    return {
      show: true
    }
  },
  props: {
    history: {
      type: Array,
      required: true
    }
  },

  created () {

  },

  methods: {
    onclickitem (val) {
      if (!this.show) {
        const index = this.history.indexOf(val)
        this.history.splice(index, 1)
      } else {
        this.$emit('onSearch', val)
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
